{ let str = ref ""
  open Parser } 
  
rule token = parse
  [' ' '\t' '\r' '\n'] { token lexbuf }
| "//"     { singlecomment lexbuf }
| "/*"     { multicomment lexbuf }
| '\"'	   { str := ""; string lexbuf }
| ';'      { SEMI }
| '['      { L_BRACKET }
| ']'      { R_BRACKET } 
| '{'      { L_BRACE }
| '}'      { R_BRACE }
| '('      { L_PAREN } 
| ')'      { R_PAREN }
| '+'      { PLUS }
| '-'      { MINUS }
| '*'      { TIMES } 
| '/'	   { DIVIDE }
| '='      { ASSIGN }
| "++"	   { INCREMENT }
| "--"	   { DECREMENT }
| "+="     { PLUSASSIGN }
| "-="     { MINUSASSIGN }
| "*="     { TIMESASSIGN }
| '#'	   { HASH }
| ".."     { RANGE }
| ','      { COMMA }
| "<-"	   { INSERT }
| "->"     { DELETE }
| '?'      { IF }
| '!'      { ELSE }
| '>'      { GT }
| '<'      { LT }
| ">="     { GEQ }
| "<="     { LEQ }
| "=="     { EQ }
| "!="     { NEQ }
| "&&"     { AND }
| "||"     { OR }
| "%-"     { DIFFERENCE }
| "%+"     { UNION }
| "%="     { INTERSECT }
| ">>"     { MAX }
| "<<"     { MIN }
| "<>"     { AVG }
| "show"   { SHOW }
| "for"    { FOR }
| "function"{ FUNCTION }
| "fun"    {FUN}
| "return" { RETURN }
| ['0'-'9']+ as lxm { LITERAL(int_of_string lxm) }
| ['a'-'z' 'A'-'Z']['a'-'z' 'A'-'Z' '0'-'9']* as lxm { ID(lxm) }
| eof { EOF }

and multicomment = parse
  "*/" { token lexbuf }  
| _  { multicomment lexbuf }

and singlecomment = parse
  "\n" { token lexbuf }  
| _  { singlecomment lexbuf }
| eof {EOF}  
  
and string = parse
| '\"'		{ STR !str }
| '\\'		{ esc lexbuf }
| _ as ch 	{ str := !str ^ (String.make 1 ch); string lexbuf }
	  	  
and esc = parse
| 't' 		{ str := !str ^ "\t"; string lexbuf }
| 'n'		{ str := !str ^ "\n"; string lexbuf }
| '\"'		{ str := !str ^ "\""; string lexbuf }
| '\\'		{ str := !str ^ "\\"; string lexbuf }